Page({
  data: {
   year:'',
   ls:['请选择类型','出差','事假','病假','年休假','丧假','产假','陪产假','婚假','调休假','看护假','工伤假',],
   value:[1,1,1,1,1,1,1],
   typ:'',
   staffid:'',
   jxfs:'',
  },
  onLoad() {
  var date = new Date();
  var ys= date .getFullYear();
  var that=this;
    that.setData({
             year:ys,
            
          });

     var that=this;

  dd.getStorage({
  key: 'staffid',
  success: function(res) 
  { 
    //console.log(res.data);
  that.setData({

   staffid:res.data
  });},});

  
  
  
  
  },
  pick:function(e){

  console.log(e.detail.value[0]);
  console.log(this.data.ls[e.detail.value[0]]);
  var tp=this.data.ls[e.detail.value[0]];
  var  that=this;
  that.setData({
     typ:tp,


  });

  },
  info:function(e)
  {
    var  that=this;
//202005170930
 //  console.log(e.detail.value);
   var bg= e.detail.value.begin;
   var ed=e.detail.value.end;
   var hr=e.detail.value.hour;
   var dy=e.detail.value.day;
   var yr=e.detail.value.year;
   var ff=that.data.typ;
   var re=e.detail.value.remark;
   var em=that.data.staffid;
   if(ff==null||ff=='')
   {
      
      dd.showToast({

     content:"请填写正确的请假或者出差类型",

     });

     

   }
   
  else if(bg.length!=12)
   {
     dd.showToast({

     content:"请填写正确的开始时间",

     });


   }else if(ed.length!=12)
   {
dd.showToast({

     content:"请填写正确的结束时间",

     });

   }else if(hr==null||isNaN(hr)){

     dd.showToast({

     content:"请填写正确的折合小时",

     });
   }else if(yr==null||isNaN(dy)){

    
     dd.showToast({

     content:"请填写正确的年度",

     });
   }else{

   

   dd.httpRequest({

        
          //提交工号和授权码，如果授权码和工号对上了就返回姓名，然后保存工号到缓存
          //url: 'https://oapi.dingtalk.com/user/getuserinfo?access_token=' + access_token + '&code=' + code,
        
          url:'http://ding.tida-lighting.com/api/Leave/apply',
           method: 'POST',
    data: {
           begin: bg,
           end: ed,
           hour:hr,
           day:dy,
           year:yr,
           typ:ff,
           empid:em,
           reason:re,
        },
        dataType: 'json',
          success: function (res) {
         

           dd.showToast({
    title: '您好',
     content:res.data.msg,
     success: () => {
       dd.navigateBack({
delta:2 //返回上一级页面
});
    
          
         }});},
        fail: (err) => {
           //dd.alert({content: JSON.stringify(err)})
           console.log(err);
        }

     });//发起结束



   }

  },
}
);
